package com.yycx.module.bus.provider.handler.haiying.tasktodo.settle.invoice;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.module.export.DictDataVo;
import com.yycx.common.base.module.export.ExportField;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.ExportInterceptor;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.admin.client.entity.BaseUser;
import com.yycx.module.bus.client.entity.BusInvoiceunit;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.enums.AmountTypeEnum;
import com.yycx.module.system.client.entity.SysCompany;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 开票申请单列表
 *
 * @author zyf
 */
@Component
public class HyInvoicePaymentPageListHandler implements PageInterceptor<BusPayment>, ExportInterceptor {


    @Override
    public void prepare(CriteriaQuery<BusPayment> cq, PageParams pageParams, EntityMap params) {
        //结算单ID
        String paymentId = params.get("paymentId");
        cq.select(BusPayment.class, "*");
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        cq.addSelect(SysCompany.class, "companyName");
        cq.addSelect(BusInvoiceunit.class, "invoiceunitName");
        cq.eq(true, "amountType", AmountTypeEnum.Invoice.getCode());
        cq.eq(true,"payment.parentId", paymentId);
        cq.ge(FlymeUtils.isNotEmpty(beginDate), "payDate", beginDate);
        cq.le(FlymeUtils.isNotEmpty(endDate), "payDate", endDate);
        cq.createJoin(SysCompany.class);
        cq.createJoin(BusInvoiceunit.class);
        cq.orderByDesc("payment.createTime");
    }
    @Override
    public void initExcelExportEntity(ExportField exportField, List list) {
        Object key = exportField.getKey();
        if (key.equals("invoiceType")) {
            List<DictDataVo> dictDataVos = new ArrayList<>();
            DictDataVo dictDataVo = new DictDataVo();
            dictDataVo.setLabel("专票");
            dictDataVo.setValue(2);
            DictDataVo dictDataVo2 = new DictDataVo();
            dictDataVo2.setLabel("普票");
            dictDataVo2.setValue(1);
            dictDataVos.add(dictDataVo);
            dictDataVos.add(dictDataVo2);
            exportField.setDictData(dictDataVos);
            exportField.setReplace();
        }
    }
}
